<?php

namespace app\modules\frontend\controllers;

use app\models\Audio;

class SiteController extends BaseController {
    public function behaviors() {
        return [
        ];
    }

    public function actions() {
        return [
            'error' => ['class' => 'yii\web\ErrorAction',],
        ];
    }

    public function actionIndex($label_id = null, $key = null) {
        $audiosQuery = Audio::find()
            ->andFilterWhere(['like', 'title', explode(' ', $key)]);
        if($label_id) {
            $audiosQuery
                ->from(['audio', 'audio_label'])
                ->andWhere(['label_id' => $label_id,])
                ->andWhere('audio.id = audio_label.audio_id');
        }
        $audios = $audiosQuery->limit(1000)->all();

        return $this->render('index', [
            'audios' => $audios
        ]);
    }
}
